package com.gitee.wsl.compose.state.ext

import com.gitee.wsl.compose.state.S
import kotlinx.coroutines.flow.Flow


/**
 * 将 Compose 的 State 转换为 Flow, 类似于 Flow.distinctUntilChanged 的行为
 *
 * val pagerState = rememberPagerState()
 * LaunchedEffect(pagerState) {
 *     snapshotFlow { pagerState.currentPage } .collect { page ->
 *         // currentPage发生变化
 *     }
 * }
 */
fun <T> S.snapshotFlow(
    block: () -> T
): Flow<T> = androidx.compose.runtime.snapshotFlow(block)